#include <iostream>

#include "CSpace.h"
#include "CMessage.h"

using namespace std;

int main(int argc, char **argv)
{
	CSpace space1("space 1");
	CSpace space2("space 2");

	CMessage msg1, msg2;

	msg1.set("this is message 1 on space 1");
	cout << "put message 1 : " << msg1.get() << " on space 1" << endl;
	cout << "current size = " << space1.write(&msg1) << endl;

	msg2.set("this is message 2 on space 2");
	cout << "put message 2 : " << msg2.get() << " on space 2" << endl;
	cout << "current size = " << space2.write(&msg2) << endl;

	vector< CSmartTemplate<CObject> > all;
	all = space1.read(NULL, space1.size(), all);
	cout << "-------------- space 1 ---------------" << endl;
	cout << "size = " << all.size() << endl;
	for(int i=0;i<all.size();i++) dynamic_cast<CMessage &>(*(all[i])).print();
	cout << "-------------------------- ---------------" << endl << endl;

	all.clear();
        all = space2.read(NULL,space2.size(), all);
        cout << "-------------- space 2 ---------------" << endl;
	cout << "size = " << all.size() << endl;
        for(int i=0;i<all.size();i++) dynamic_cast<CMessage &>(*(all[i])).print();
        cout << "-------------------------- ---------------" << endl << endl;
}
